/*
 * dynamic_library.cpp
 *
 *  Created on: 2008-8-13
 *      Author: fanliangliang
 */

#include "dynamic_library.h"

BEGIN_NAMESPACE_TOXIC

DynamicLibrary::DynamicLibrary(const string& pathname)
:_handle(0)
,_pathname(pathname) {
	string::size_type pos = pathname.find_last_of("/\\");
	if (pos != string::npos) {
		_filename = pathname.substr(pos + 1);
	}
	else {
		_filename = pathname;
	}
	_handle = _load_library(_pathname.c_str());
}

DynamicLibrary::~DynamicLibrary() {
	if (_handle != 0) {
		_close_library(_handle);
	}
}

bool DynamicLibrary::isValid() const {
	return _handle != 0;
}

const string& DynamicLibrary::filename() const {
	return _filename;
}

const string& DynamicLibrary::pathname() const {
	return _pathname;
}

void* DynamicLibrary::lookup(const string& symbol) const {
	return _lookup_symbol(_handle, symbol.c_str());
}

END_NAMESPACE_TOXIC
